package api

import (
	"api-gateway/handler/resp"
	"fmt"
	"github.com/gin-gonic/gin"
	"path"
)

func VideoAdd(c *gin.Context) {

}

func FileUpload(c *gin.Context) {
	file, _ := c.FormFile("file")

	ext := path.Ext(file.Filename)
	if ext != ".mp4" && ext != ".avi" {
		resp.Error(c, 500, "上传格式只能是.mp4或者.avi", false)
		return
	}
	if file.Size > 200*1024*1024 {
		resp.Error(c, 500, "上传文件过大", false)
		return
	}
	dst := "D:\\phpstudy_pro\\WWW\\" + file.Filename

	err := c.SaveUploadedFile(file, dst)
	if err != nil {
		resp.Error(c, 500, "上传文件错误", false)
		return
	}

	resp.Success(c, "上传成功", fmt.Sprintf("http://localhost:/%s", file.Filename))
	//resp.Success(c, "上传成功", url)
}
